package cn.sdhuijin.healthexam.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import cn.sdhuijin.healthexam.DatabaseHelper;
import cn.sdhuijin.healthexam.ExitApplication;
import cn.sdhuijin.healthexam.R;
import cn.sdhuijin.healthexam.control.AbstractControlActivity;
import cn.sdhuijin.healthexam.util.Constants;

/**
 * 高血压随访第二页
 * 
 * 
 * @author sunping
 */
public class EditVisitHypertensionSecondActivity extends
		AbstractControlActivity implements OnClickListener {

	private String createDate;
	private DatabaseHelper databaseHelper = new DatabaseHelper(this);

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_edit_hypertension_second);
		ExitApplication.getInstance().addActivity(this);

		Intent intent = getIntent();
		Bundle bundle = intent.getBundleExtra("bundle");
		if (bundle != null) {
			createDate = bundle.getString("createDate");
		}
		setCurrentEditUserName(createDate);

		addRadioGroupView(R.id.rad_medical_behavior, "遵医行为");
		addEditTextView(R.id.edt_auxiliarys_exam, "辅助检查");
		addRadioGroupView(R.id.rad_compliance, "服药依从性");
		addRadioGroupView(R.id.rad_drug_reactions, "药物不良反应");
		addRadioGroupView(R.id.rad_classification, "此次随访分类");
		addEditTextView(R.id.edt_drug_name_first, "药物名称一");
		addEditTextView(R.id.edt_drug_num_first, "药物一次数");
		addEditTextView(R.id.edt_drug_amount_first, "药物一用量");
		addEditTextView(R.id.edt_drug_name_second, "药物名称二");
		addEditTextView(R.id.edt_drug_num_second, "药物二次数");
		addEditTextView(R.id.edt_drug_amount_second, "药物二用量");
		addEditTextView(R.id.edt_drug_name_third, "药物名称三");
		addEditTextView(R.id.edt_drug_num_third, "药物三次数");
		addEditTextView(R.id.edt_drug_amount_third, "药物三用量");
		addEditTextView(R.id.edt_drug_name_other, "其他药物名称");
		addEditTextView(R.id.edt_drug_num_other, "其他药物次数");
		addEditTextView(R.id.edt_drug_amount_other, "其他药物用量");
		addEditTextView(R.id.edt_referral_reason, "转诊原因");
		addEditTextView(R.id.edt_referral_place, "转诊机构及科别");
		addEditTextView(R.id.edt_next_date, "下次随访日期");
		addEditTextView(R.id.edt_visit_doctor, "随访医生签名");
		addEditTextView(R.id.edt_suggestion, "指导意见");

		controlManager.setPropertiesPath(Constants.PROPERTIES_PATH + createDate
				+ ".txt");
		Log.i(EditPersonDocFirstActivity.class.getSimpleName(), "文件路径： "
				+ Constants.PROPERTIES_PATH + createDate + ".txt");
		controlManager.toControl();

		setEditTextListener(R.id.edt_next_date);
		setButtonListener(this, R.id.btn_previous, R.id.btn_complete);
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent();
		Bundle bundle = new Bundle();
		int clickId = (Integer) v.getId();
		switch (clickId) {
		case R.id.btn_complete:
			controlManager.toProperties();
			databaseHelper.updateIndexTable(createDate);
			this.toastInformation(R.string.toast_submit_info);
			intent.setClass(this, IndexActivity.class);
			startActivity(intent);
			finish();
			break;
		case R.id.btn_previous:
			controlManager.toProperties();
			intent.setClass(this, EditVisitHypertensionFirstActivity.class);
			bundle.putString("createDate", createDate);
			intent.putExtra("bundle", bundle);
			startActivity(intent);
			finish();
			break;
		default:
			break;
		}
	}

}
